<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <title></title>
    <script type="text/javascript" src="../applyandactivate/js/stats.js" charset="UTF-8"></script>
    <link rel="stylesheet" href="../applyandactivate/css/frozen.css">
    <link rel="stylesheet" href="../applyandactivate/css/style.css">
    <script src="../applyandactivate/lib/zepto.min.js"></script>
    <script src="../applyandactivate/js/frozen.js"></script>
    <script src="../js/link.js"></script>
    <script src="../applyandactivate/js/age.js"></script>
    <script src="js/id.js"></script>
</head>

<body ontouchstart>
    <header class="ui-header ui-header-stable ui-border-b xc_header">
        <i class="ui-icon-return" onclick="history.back()"></i>
        <h1 class="ui-txt-feeds xc_header_h1">个人信息</h1>
    </header>
    <section class="ui-container">
        <!--<h2 class="IDtit"></h2>-->
        <div id="form">
            <div class="ui-form">
                <form action="#" id="userInfo">
                    <div class="ui-form-item xc_li_bottom">
                        <label for="username">
                            姓名<i class="ui-txt-red">*</i>
                        </label>
                        <input id="username" placeholder="请输入姓名" name="username" type="text" value="">
                        </a>
                    </div>
                    <!-- <div class="ui-form-item xc_li_bottom">
                            <label for="phoneNum">
                                手机号码<i class="ui-txt-red">*</i>
                            </label>
                            <input id="phoneNum" name="phoneNum" type="text" placeholder="请输入手机号码">
                            </a>
                        </div> -->
                    <div class="ui-form-item ui-border-b">
                        <label class="">
                            证件类型<i class="ui-txt-red">*</i>
                        </label>
                        <div class="ui-select xc_option">
                            <select id="xc_idSelect">
                                <option selected value="CID">身份证</option>
                                <!--<option value="OTHER">军官证</option>
                                <option value="OTHER">护照</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="ui-form-item ui-border-b">
                        <label>
                            证件号码<i class="ui-txt-red">*</i>
                        </label>
                        <input id="xc_idNum" type="text" placeholder="请输入证件号码" />
                    </div>
                    <div class="ui-form-item ui-border-b xc_birthDate">
                        <label>
                            出生日期<i class="ui-txt-red">*</i>
                        </label>
                        <input id="birthDate" type="text" value="" placeholder="请输入出生日期" />
                    </div>
                    <div class="ui-form-item  ui-border-b xc_sex">
                        <div class="fl" style="width: 30%;">
                            性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别<i class="ui-txt-red">*</i>
                        </div>
                        <div class="fl" id="sex" style="width: 70%;">
                            <label class="ui-radio" for="radio">
                                <input id="sex_man" type="radio" name="sex" value="男">男
                            </label>
                            <label class="ui-radio" for="radio">
                                <input id="sex_woman" type="radio" name="sex" value="女">女
                            </label>
                        </div>
                    </div>
                    <div class="ui-form-item ui-border-b">
                        <label class="">
                            申领类别<i class="ui-txt-red">*</i>
                        </label>
                        <div class="ui-select xc_option">
                            <select class="xc_select_js" id="xc_select_js">
                                <option selected value="10">首次申请</option>
                                <option value="20">换发护照</option>
                                <option value="30">补发护照</option>
                            </select>
                        </div>
                    </div>
                    <div class="ui-form-item xc_select_yy ">
                        <div class="fl" style="width: 30%;">
                            原&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;因<i class="ui-txt-red">*</i>
                        </div>
                        <div class="fl" id="xc_applyCase" style="width: 70%;">
                            <div id="">
                                <label class="ui-radio" for="radio">
                                    <input type="radio" name="applyCase" value="1">原护照丢失
                                </label>
                            </div>
                            <div id="">
                                <label class="ui-radio" for="radio">
                                    <input type="radio" name="applyCase" value="2">原护照被盗或损毁
                                </label>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
    <!-- /.ui-container-->
    <footer class="ui-footer">
        <button form="userInfo" class="xc_btn" type="button">确定</button>
    </footer>
</body>

</html>
<script>
//手机号验证

// var phone_pattern = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/;
//    $("#phoneNum").blur(function(){
//            if (!phone_pattern.test($("#phoneNum").val())) {
//           alert("手机号填写错误");
//        }
//    })
//身份证判别
function IDjudge() {
    if ($("#xc_idSelect").val() == "CID") {
        $(".xc_birthDate").hide();
        $(".xc_sex").hide();
        birthChecked();
    } else {
        $(".xc_birthDate").show();
        $("#birthDate").val("");
        $(".fl input").removeAttr("checked");
        $(".xc_sex").show();

        // $("#sex_woman").removeAttr("checked");
    }
}

function IDjudge1() {
    if ($("#xc_idSelect").val() == "CID" && $("#xc_idNum").val().length == 18) {
        $(".xc_birthDate").hide();
        $(".xc_sex").hide();
        birthChecked();
    } else {
        $(".xc_birthDate").show();
        $("#birthDate").val("");
        $(".fl input").removeAttr("checked");
        $(".xc_sex").show();
        // $("#sex_woman").removeAttr("checked");
    }
}


//出生日期
function birthChecked() {
    var IDNumber = $("#xc_idNum").val();
    var birth_date = "";
    birth_date = IDNumber.substring(6, 14);
    $("#birthDate").val(birth_date);
}

// 选择性别
function sexChecked() {
    var applicant_sex = null;
    var psidno = $("#xc_idNum").val();
    var last = psidno[psidno.length - 2];
    if (last % 2 != 0) {
        console.log("男")
            // $("#sex_man").click().attr("disabled");
        $("#sex_man").attr("checked", "checked");
    } else {
        console.log("女")
            // $("#sex_woman").click().attr("disabled");
        $("#sex_woman").attr("checked", "checked");
    }
}
// 身份验证
function authentication() {
    var pattern = /^([1-9]{1})([0-7]{1})(\d{13}$|\d{16}$|\d{15}(\d|X|x))$/;
    var IDNumber = $("#xc_idNum").val();
    console.log(IDNumber)
    if ($("#xc_idSelect").val() == "CID") {
        console.log("是身份证");
        if (pattern.test(IDNumber)) {
            console.log("正确");
        } else {
            alert("请填写正确的证件号码");
        }
    } else {
        console.log("不是身份证");
    }
}
$("#xc_idNum").change(function() {
    IDjudge1();
    if ($("#xc_idSelect").val() == "CID") {
        authentication();
        if ($("#xc_idNum").val().length !== 0 && $("#xc_idNum").val().length == 18) {
            birthChecked();
            sexChecked();
            console.log("调用了身份0");
            authentication();

        }
    }

})
$(".xc_btn").click(function() {
    if ($("#username").val()!="") {
        if (!checkCard()) {
            return;
        } else {
            if ($("#birthDate").val().length !== 8) {
                alert("请填写正确的出生日期");
            } else {
                if (!($("#sex_man").is(":checked") || $("#sex_woman").is(":checked"))) {
                    alert("请选择性别");
                } else {
                    ajaxUserInfo();//调用查询接口
                }
            }

        }
    }else{
        alert("请填写姓名");
    }
})

$(function() {

        $(".xc_birthDate").hide();
        $(".xc_sex").hide();

        $("#xc_idSelect").change(function() {
            IDjudge();
        })
        $(".xc_select_yy").hide();
        $(".xc_select_js").change(function() {
            if ($(".xc_select_js").val() == "10") {
                $(".xc_select_yy").hide();
                $('#xc_applyCase input').val("");
            } else {
                $(".xc_select_yy").show();
            }
        })
    })
    //ajax调用

// ------


function ajaxUserInfo() {
    var birthDate = $("#birthDate").val();
    var userAge = jsGetAge(birthDate);
    if ( userAge< 18) {
        //将字段缓存到session
        var sex = $('#sex input:checked').val() || sexChecked();
        window.sessionStorage.setItem("sex", sex); //性别
        var applyCase = $('#xc_applyCase input:checked ').val() || '';
        window.sessionStorage.setItem("applyCase", applyCase); //护照类型原因
        var applyType = $("#xc_select_js").val(); //类型
        window.sessionStorage.setItem("applyType", applyType);
        var name = $("#username").val();
        window.sessionStorage.setItem("name", name); //用户名字
        var cardType = $("#xc_idSelect").val();
        window.sessionStorage.setItem("cardType", cardType); //身份证
        var cardNO = $("#xc_idNum").val();
        window.sessionStorage.setItem("cardNO", cardNO); //身份证号
        var birthday = $("#birthDate").val();
        window.sessionStorage.setItem("birthday", birthday); //出生日期
        $.ajax({
            url: activatePath + "/pingan/findActivateRecord?idNo=" + cardNO,
            type: 'post',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            error: function(datas) {
                alert("出错了！");
            }, //错误执行方法
            success: function(datas) {
                    if (datas["success"]) {
                        if (datas["obj"]["code"] == 10) {
                            window.location.href = "guardianInfo.html?userAge="+userAge;
                        } else if (datas["obj"]["code"] == 20) {
                            window.location.href = "thanks.html?birth=17";
                        }
                    } else {
                        alert(datas["message"]);
                    }
                } //成功执行方法
        })

    } else {
        window.location.href = "thanks.html?birth=19";
    }
}
//------------
</script>
